package com.dgut.shopManage.web;

import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dgut.common.util.ExtAjaxResponse;
import com.dgut.common.util.ExtPageable;
import com.dgut.shopManage.entity.dto.ResultsDTO;
import com.dgut.shopManage.entity.dto.ResultsQueryDTO;
import com.dgut.shopManage.service.IResultsService;

@Controller
@RequestMapping("/results")
public class ResultsContreller {
	@Autowired
	private IResultsService resultsService;
	
	@RequestMapping("/resultsFindPage")
	public @ResponseBody Page<ResultsDTO> findPage(ResultsQueryDTO resultsQueryDTO,ExtPageable pageable) 
	{
		Page<ResultsDTO> page =  resultsService.findAll(resultsQueryDTO.getSpecification(resultsQueryDTO), pageable.getPageable());
		return page;
	}
	
	@RequestMapping("/resultsDelete")
	public @ResponseBody ExtAjaxResponse deleteResults(@RequestParam Long[] ids) 
	{
		try {
			List<Long> idLists = Arrays.asList(ids);
			if(null!=idLists) {
				for (int i = 0; i < ids.length; i++) {
					resultsService.delete(idLists.get(i));
				}
			}
			return new ExtAjaxResponse(true,"操作成功！");
		} catch (Exception e) {
			return new ExtAjaxResponse(false,"操作失败！");
		}
	}
}
